/**   
 * @Title: ChooseLogServiceImplementation.java 
 * @Package cn.edu.cdtu.healthserver.service.impl 
 * @Description: TODO 
 * @author  
 * @date 
 * @version V0.0   
 */
package cn.edu.cdtu.healthserver.service.impl;

import java.util.List;

import cn.edu.cdtu.healthserver.dao.ChooseLogDao;
import cn.edu.cdtu.healthserver.dao.impl.ChooseLogDaoImplementation;
import cn.edu.cdtu.healthserver.domain.Choose;
import cn.edu.cdtu.healthserver.domain.ChooseLog;
import cn.edu.cdtu.healthserver.domain.TestLog;
import cn.edu.cdtu.healthserver.service.ChooseLogService;

/** 
 * @ClassName: ChooseLogServiceImplementation 
 * @Description: TODO
 * @author 
 * @date 
 *  
 */
public class ChooseLogServiceImplementation implements ChooseLogService {

	private ChooseLogDao chooseLogDao = new ChooseLogDaoImplementation();
	
	/* (non-Javadoc)
	 * <p>Title: getChooseLogs</p> 
	 * <p>Description: </p> 
	 * @param testLog
	 * @return 
	 * @see cn.edu.scu.healthserver.service.ChooseLogService#getChooseLogs(cn.edu.scu.healthserver.domain.TestLog)
	 */
	@Override
	public List<ChooseLog> getChooseLogs(TestLog testLog) {
		// TODO Auto-generated method stub
		return chooseLogDao.query(testLog);
	}

	/* (non-Javadoc)
	 * <p>Title: createChooseLog</p> 
	 * <p>Description: </p> 
	 * @param testLog
	 * @param choose
	 * @return 
	 * @see cn.edu.scu.healthserver.service.ChooseLogService#createChooseLog(cn.edu.scu.healthserver.domain.TestLog, cn.edu.scu.healthserver.domain.Choose)
	 */
	@Override
	public ChooseLog createChooseLog(TestLog testLog, Choose choose) {
		// TODO Auto-generated method stub
		ChooseLog newLog = new ChooseLog(
				testLog.getId(),
				choose.getQuestion_id(),
				choose.getId()
				);
		if (!chooseLogDao.add(newLog)) {
			return null;
		}
		List<ChooseLog> logs = this.getChooseLogs(testLog);
		for (ChooseLog chooseLog : logs) {
			if (newLog.equalsWithoutId(chooseLog)) {
				return chooseLog;
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * <p>Title: updateChooseLog</p> 
	 * <p>Description: </p> 
	 * @param chooseLog
	 * @return 
	 * @see cn.edu.scu.healthserver.service.ChooseLogService#updateChooseLog(cn.edu.scu.healthserver.domain.ChooseLog)
	 */
	@Override
	public String updateChooseLog(ChooseLog chooseLog) {
		// TODO Auto-generated method stub
		String resultString = null;
		if(chooseLogDao.update(chooseLog)){
			resultString = "更新测试详情记录成功！";
		}else {
			resultString = "更新测试详情记录失败！";
		}
		return resultString;
	}

}
